package org.supper.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author huqi
 */
@Component
public class TokenConfig {

    private static final String SINGLE_KEY = "user:123456";
    @Resource
    private RedisConnectionFactory redisConnectionFactory;
    @Bean
    TokenStore tokenStore(){
        return new RedisTokenStore(redisConnectionFactory);
    }
    @Bean
    private JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey(SINGLE_KEY); // 对称密钥,资源服务器使用该密钥来验证
        return converter;
    }

}
